window.Organizations = (function($, module) {

	/*function init() {
		
	
		initPageInfo(); 
		//getUserMeuns();
	}*/
	function initPageInfo() {
		CommonUtils.getAjaxData({url:'/organization/organizationList',data:{},async:false,type:'GET'},function(data){
            PageUtils.refreshPageInfo({element:'tablelPage',async:true,type:'GET',url :'/organization/organizationList',data:{},callback : showOrganization},data['page']);
            showOrganization(data);
        });
	}
	
	//点击当前节点的所有子节点的数据
	function getDataForAllNodes(idsArray){
		CommonUtils.getAjaxData({url:'/organization/organizationList',data:{"idsArray":idsArray},async:false,type:'GET'},function(data){
            PageUtils.refreshPageInfo({element:'tablelPage',async:true,type:'GET',url :'/organization/organizationList',data:{},callback : showOrganization},data['page']);
            showOrganization(data);
        });
	}
	
	function showOrganization(Organization) {
		var _OrganizationList = $("#organizationList");
		_OrganizationList.html("");
	/*	var datas = eval(Organization["organizationList"]);*/
		var datas = Organization["organizationList"];
		$.each(
						datas,
						function(item, obj) {
							var dom = "";
							dom += "<tr class='contentText list_list '>";
							dom += "<td  style='width : 50px !important;' align='center'><input type='checkbox' class='input_checkBox' name='id' id='"
								+ obj.id
								+ "' value='"
								+ obj.id
								+ "'/></td>";
							/*if(hasOperatorButton('ORGANIZATION_UPDATE',button)){*/
								dom += "<td class='cursor' onclick='updateOrg("+ obj.id +")'>"
									+ obj.orgaName
									+ "</td>";
							/*}else{
								dom += "<td>"
									+ obj.orgaName
									+ "</td>";
							}*/
							
							dom += "<td>" + obj.orgaCode + "</td>";
							dom += "<td>" + getParentName(obj.parentOrgId, datas);
							
							 + "</td>";
							dom += "</tr>";
							
							_OrganizationList.append(dom);
						});
		/*$("tbody tr:odd").css("background", "#EBF5FF");*/
		// ie8隔行变色
        CommonUtils.ie8TrChangeColor();
	}
	
	function getParentName(orgaParentId, datas){
		if(orgaParentId == 0){
				return "西安导引科技公司";
			}
		for (var i = 0; i < datas.length; i++){
	
			if(orgaParentId == datas[i].id){
				return datas[i].orgaName;
			}else if(orgaParentId == datas[i].parentOrgId){
				return datas[i].parentOrgaName;
			}
			
		}
		
	}

	function delOrganization() {
		var list = [];
		var checks = $("input[name='id']:checked");
		$.each(checks, function(index, obj) {
			list.push(obj.value);
		});
		if (!list.length > 0) {
			if(checks.length>0){
				alert("所选的组织机构不可删除!!");
			}else{
				alert("请选择要删除的组织机构!!");
			}
				
			return;
		}
		confirm("确定要删除吗?",function(data){
			/*if(data){
				$.ajax({
					type : 'POST',
					url : '/organization/delOrganization',
					cache : false,
					data : JSON.stringify(list),
					contentType : 'application/json; charset=utf-8',
					async : true,
					success : function(data) {
						if (data == 'delSuccess') {
							//进行左边树形结构的刷新
							window.location.href = "/organization/organizationPage";
							//alert("删除成功");
						} else if (data == "userExist") {
							alert("组织机构数据正在被使用：无法删除!");
						} else if(data == "organization"){
							alert("组织机构下存在子机构：无法删除!")
						} else {
							alert("系统错误");
						}
						var current = PageUtils._currentPage['tablelPage'];
						PageUtils.pageClick(current, 'tablelPage');
					}
				});
			}*/
			});
	}

	/**
	 * 异步查询仓库记录页数
	 */
/*	function showOrganizationPage(Organization) {
		var url = '/organization/organizationList';
		PageUtils.refreshPageInfo({
			element : 'organizationPage',
			url : url,
			callback : showOrganization
		}, Organization['page']);
	}*/
	
	module.init = init;
	module.getDataForAllNodes=getDataForAllNodes;
	module.delOrganization = delOrganization;
	return module;
}($, window.Organizations || {}));
$(function() {
	Organizations.init();
});